package com.lhf.azkaban.springbatch.example.job.dao;

import org.springframework.batch.core.repository.dao.JdbcJobInstanceDao;
import org.springframework.jdbc.support.incrementer.AbstractDataFieldMaxValueIncrementer;

/**
 * @Author:95780
 * @Date: 18:07 2019/11/25
 * @Description:
 */
public class MyJdbcJobInstanceDao extends JdbcJobInstanceDao {
    private static final String GET_COUNT_BY_JOB_NAME = "SELECT COUNT(1) from BATCH_JOB_INSTANCE "
            + "where JOB_NAME=?";


    @Override
    public void afterPropertiesSet() throws Exception {

        setJobIncrementer(new AbstractDataFieldMaxValueIncrementer() {
            @Override
            protected long getNextKey() {
                return 0;
            }
        });

        super.afterPropertiesSet();

    }


    public int countJobInstances(String name) {
        return getJdbcTemplate().queryForObject(getQuery(GET_COUNT_BY_JOB_NAME), Integer.class, name);
    }
}
